enum COLOR{
    FANG    = 0x00,
    MEI     = 0x01,
    HONG    = 0x02,
    HEI     = 0x03,
    JOKER   = 0x04,
}

enum SIZE{
    _A= 0x01,
    _2= 0x02,
    _3= 0x03,
    _4= 0x04,
    _5= 0x05,
    _6= 0x06,
    _7= 0x07,
    _8= 0x08,
    _9= 0x09,
    _10= 0x0a,
    _J= 0x0b,
    _Q= 0x0c,
    _K= 0x0d,
    _BJOKER= 0x0e,
    _RJOKER= 0x0f,
    COUNT = 16,
}

export const CARD_INVALID = 0x00;

export const Card = {
    COLOR:COLOR,
    SIZE:SIZE,

    /**
     * getCard
     * @param {number} color
     * @param {number} size
     * @returns {number}
     */
    getCard : function(color:COLOR, size:SIZE) {
        return (color << 4) | size;
    },
    /**
     * getColor
     * @param {number} card
     * @returns {number}
     */
    getColor:function(card:number) {
        return ((card & 0xf0) >> 4);
    },
    /**
     * getSize
     * @param {number} card
     * @returns {number}
     */
    getSize:function(card:number) {
        return (card & 0x0f);
    },

    isBack(card:number):boolean{
        return card == 0x00;
    }
};

export const CARDS_TO_HEX_STR = function (cards) {
    let a = "[";
    for(let i=0;i<cards.length;i++){
        if(cards[i]>0x10) a=a+"0x"+cards[i].toString(16);
        else a=a+"0x0"+cards[i].toString(16);
        if(i!=cards.length-1) a = a+",";
    }
    a = a+"]";
    return a;
};

export const CARDS_TO_ASCII_STR = function (cards) {
//♠♥♦♣
    let a = "[";
    for(let i=0;i<cards.length;i++){
        let color = (cards[i] & 0xf0) >> 4;
        let size = cards[i] & 0x0f;
        if(color==COLOR.FANG){
            a=a+"♦"
        }else if(color==COLOR.MEI){
            a=a+"♣"
        }else if(color==COLOR.HONG){
            a=a+"♥"
        }else if(color==COLOR.HEI){
            a=a+"♠"
        }
        if(size==SIZE._RJOKER){
            a=a+"★"
        }else if(size==SIZE._BJOKER){
            a=a+"☆"
        }else if(size==SIZE._A){
            a=a+"A"
        }else if(size==SIZE._K){
            a=a+"K"
        }else if(size==SIZE._Q){
            a=a+"Q"
        }else if(size==SIZE._J){
            a=a+"J"
        }else{
            a=a+size
        }
        if(i!=cards.length-1) a = a+",";
    }
    a = a+"]";
    return a;
}
export const enum CARD_TYPE{
    NULL,
    DAN_ZHANG,                      //单张1
    DUI_ZI,                         //对子2
    SAN_ZHANG,                      //三张3
    SAN_DAI_DUI,                    //三带对
    ER_SHUN,                        //二顺5
    SAN_SHUN,                       //三顺6
    FEI_JI_WIN,                     //蝴蝶（飞机带翅膀)
    SI_ZHA,                         //四炸7
    WU_ZHA,                         //五炸8
    LIU_ZHA,                        //六炸10
    QI_ZHA,                         //七炸12
    BA_ZHA,                         //八炸13
    ////////////////////////////////////////////////////
    JIU_ZHA,                        //九炸14
    SHI_ZHA,                        //十炸15
    SHI_YI_ZHA,                     //十一炸16
    SHI_ER_ZHA,                     //十二炸17
    TIAN_WANG,                      //天王炸最大
}

export const GET_WEIGHT = function(type:CARD_TYPE) {
    if (type < CARD_TYPE.SI_ZHA){
        return 0;
    }

    if(type <= CARD_TYPE.SHI_ER_ZHA){
        return type;
    }
};

export class Comb{
    type:CARD_TYPE;
    cards:Array<number>;
    max_card:number;
    constructor(type:CARD_TYPE,max_card:number,cards:Array<number>){
        this.type = type;
        this.max_card = max_card;
        this.cards = cards.slice(0);
    }
}

/////////////////////////////////////////////////////////////////////////////////
export const MAX_PLAYER = 4;
export const BASE_HAND_CARD = 25;
export const DI_ZHU_CARD = 8;
export const INVALID_SEAT = -1;

export const HAS_POWER = function(power:number,action:number) {
    return (power & action) > 0;
}

export const enum Base{
    base1 = 1,
    base2 = 2,
    base3 = 3,
}
//叫地主行为
export const enum BankerAction{
    NULL        = 0x00000,
    NOT_QIANG   = 0x00001,   //不抢
    QIANG_1     = 0x00002,   //1分
    QIANG_2     = 0x00004,   //2分
    QIANG_3     = 0x00008,   //3分
}

export const enum PlayerAction{
    NULL        = 0x00000,
    NOT_PLAY    = 0x00001,   //不出
    PLAY        = 0x00002,   //出牌
    CHAO_DI     = 0x00004,   //抄底
}

export const enum EndType{
    END_NULL        = 0,
    END_DIZHU       = 1,    // 地主胜
    END_NONGMING    = 2,    // 农民胜
}


export const enum GAME_STEP{
    NULL          = 0,
    GAME_START    = 1,         //开始游戏
    TAKE_FIRST    = 2,         //抓牌
    JIAO_DI_ZHU   = 3,         //叫地主
    SHOW_DI_PAI   = 4,         //展示底牌
    PLAY_CARD     = 5,         //打牌
    WIN_LOST      = 6,         //结算
    GAME_END      = 7,         //结束游戏
}


